package com.service.qrode;

import com.model.qrcode.Qrode;
import com.service.menu.MenuSeviceImpl;
import com.util.WeixinUtil;
import net.sf.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import java.io.Serializable;

/**
 * Created by Administrator on 2016/11/10.
 */
@Service("qrodeService")
public class QrodeServiceImpl implements QrodeService{
    private static Logger log = LoggerFactory.getLogger(QrodeServiceImpl.class);

    // 二维码创建（POST） 限1000（次/天）
    public static String qrode_create_url =" https://api.weixin.qq.com/cgi-bin/qrcode/create?access_token=ACCESS_TOKEN";

    //获取二维码
    public static String qrode_get_url="https://mp.weixin.qq.com/cgi-bin/showqrcode?ticket=TICKET";

    public JSONObject add(Qrode qrode, String accessToken){
        // 拼装创建菜单的url
        String url = qrode_create_url.replace("ACCESS_TOKEN", accessToken);
        // 将菜单对象转换成json字符串
        String jsonQrode = JSONObject.fromObject(qrode).toString();
        // 调用接口创建菜单
        JSONObject jsonObject = WeixinUtil.httpRequest(url, "POST", jsonQrode);
        return jsonObject;
    }

}
